package org.scboy.utils.entitys.coobi;

import cn.hutool.core.util.PageUtil;

public class Limit {
	
	private int currentPage;
	
	private int pageSize;
	//开始条数
	private int start;
	//偏移条数
	private int limit;
	
	public int getStart() {
		return start;
	}
	
	public int getLimit() {
		return limit;
	}
	
	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public int getPageSize() {
		return pageSize;
	}
	
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	
	public static Limit createLimit(int pageNo,int pageSize){
		pageNo=pageNo-1;
		if(pageNo<0) {
			pageNo=0;
		}
		int [] pageArray=PageUtil.transToStartEnd(pageNo, pageSize);
		Limit limitModel=new Limit();
		limitModel.start=pageArray[0];
		limitModel.limit=pageSize;
		return limitModel;
	}
	
	public Limit init(){
		int [] pageArray=PageUtil.transToStartEnd(this.currentPage, this.pageSize);
		this.start=pageArray[0];
		this.limit=pageSize;
		return this;
	}
}
